#include "debug.h"
#include "../DDIC/AllDDIC.h"
#include "usbd_cdc.h"
#include "IOConfig.h"

extern void GenW_PANEL_normal_SPI_Write_code(u8 SPI_Mode,u8 channel ,u8 para[]);
extern u8 GenR_PANEL_SPI4_Read_u8_Data(u8 SPI_Mode,u8 channel,u8 reg,u8 para[],u8 back_num);

u8 ft_bufferR[50];
u8 ft_bufferG[50];
u8 ft_bufferB[50];


void FT2306_Write_Register(USBD_HandleTypeDef *pdev,uint8_t  ep_addr,u8 SigMode ,u8 channel,u8* buffer,u16 LP_B7_Data,u16 HS_B7_Data)
{
	 if((SigMode == SPI3_Mode)||(SigMode == SPI4_Mode))          //3Ïß 4Ïß8bit SPI Ä£Ê½
    {
        GenW_PANEL_SPI_Write_code_cuihuashan(SigMode,channel,buffer);  
    }
    else if((SigMode == Video_Mode)||(SigMode == CMD_Mode))
    {
        if(SigMode != CMD_Mode)
            SSD2828_W_Reg(SigMode,channel,0xB7,(HS_B7_Data|0x0010)&0XFFFD);
        delay_ms(5);
        SSD2828_W_Array(SigMode,channel,buffer,2);
        delay_ms(50);
        SSD2828_W_Reg(SigMode,channel,0xB7,HS_B7_Data);
    }
    buffer[4] = Uart_Error_None;
    STM2PC_RM671xx(pdev,CDC_IN_EP,buffer,buffer[2]+3);           //·µ»Ø Ð´¼Ä´æÆ÷×´Ì¬  £ºok  
}
void FT2306_Read_Register(USBD_HandleTypeDef *pdev,uint8_t  ep_addr,u8 SigMode ,u8 channel,u8* buffer,u16 LP_B7_Data,u16 HS_B7_Data)
{
     if((SigMode == SPI3_Mode)||(SigMode == SPI4_Mode))          //3Ïß 4Ïß8bit SPI Ä£Ê½
    {
        switch(buffer[3]&0x0F)
        {
            case 0x00:      ////CMD1 read function
                SPI_PANEL_Write_code(SigMode,channel,0xfe,0x00);
								SPI4_PANEL_Read_u8_Data_cuihuashan_page_Alan(SigMode,channel,buffer[3],buffer[4],buffer,buffer[5]); 
                delay_ms(5);
                STM2PC_RM671xx(pdev,CDC_IN_EP,buffer,(buffer[2])+3);           //·µ»Ø ¶ÁÈ¡µÄ ¼Ä´æÆ÷Êý¾Ý  £ºok  
                break;
            
            default :   ////CMD2 read function
                //buffer[4] = SPI4_PANEL_Read_u8_Data_page(SigMode,channel,buffer[4],buffer[3]); 
								buffer[5] = SPI4_PANEL_Read_u8_Data_cuihuashan_page(SigMode,channel,buffer[3],buffer[4]);
                delay_ms(5);
                STM2PC_RM671xx(pdev,CDC_IN_EP,buffer,(buffer[2])+3);           //·µ»Ø ¶ÁÈ¡µÄ ¼Ä´æÆ÷Êý¾Ý  £ºok  
                break;
        }

    }
    else if((SigMode == Video_Mode)||(SigMode == CMD_Mode))
    {
        if(SigMode == Video_Mode)  //RGB+SPI= MIPI
            SSD2828_W_Reg(SigMode,channel,0xB7,((HS_B7_Data|0x0010)&0XFFFD)|0x0080);      
        else
            SSD2828_W_Reg(SigMode,channel,0xB7,LP_B7_Data|0x0080);
        delay_ms(5);
        SSD2828_W_Reg(SigMode,channel,0xC1,0x0002); 
        SSD2828_W_Reg(SigMode,channel,0xC0,0x0001); 
        SSD2828_W_Reg(SigMode,channel,0xBC,0x0001);
        SSD2828_W_Reg(SigMode,channel,0xBD,0x0000);                                    
        for(i=0;i<3;i++)
        {
            SSD2828_W_Cmd(SigMode,channel,0xBF);
            SSD2828_W_Data(SigMode,channel,buffer[3]);
            if(SigMode == Video_Mode)  //RGB+SPI= MIPI   
                SSD2828_W_Reg(SigMode,channel,0xD4,0x00FA);  
            delay_ms(25);
            buffer[4]=SSD2828_R_Reg(SigMode,channel,0xFF);
        }                              
        SSD2828_W_Reg(SigMode,channel,0xB7,HS_B7_Data);
        delay_ms(5);
        STM2PC_RM671xx(pdev,CDC_IN_EP,buffer,buffer[2]+3);           //·µ»Ø ¶ÁÈ¡µÄ ¼Ä´æÆ÷Êý¾Ý  £ºok  	
    } 
}

void FT2306_Write_Gamma(USBD_HandleTypeDef *pdev,uint8_t  ep_addr,u8 SigMode ,u8 channel,u8* buffer,u16 LP_B7_Data,u16 HS_B7_Data)
{
    u8 buffer1[7];
    u8 i,j,k=0,temp;
	  u8 m = 0x00;
					

		SSD2828_W_Reg(SigMode,channel,0xB7,(HS_B7_Data|0x0410)&0XFFFD);
		delay_ms(2);		

		 if((buffer[4]&0xFF)==0x01)  //NORMAL
			{
				if((buffer[3]&0xFF)==0x00)
				{
					SSD2828_W_Reg(SigMode,channel,0xBC,48); 
		      SSD2828_W_Cmd(SigMode,channel,0xBF);	
		      SSD2828_W_Data(SigMode,channel,0xE2); // Normal GAMMA RED 
		      for(i=0; i<47; i++)
		      {     
			      SSD2828_W_Data(SigMode,channel,ft_bufferR[i]);	
		      }
				}
				else if((buffer[3]&0xFF)==0x01)
				{
					SSD2828_W_Reg(SigMode,channel,0xBC,48); 
		      SSD2828_W_Cmd(SigMode,channel,0xBF);	
		      SSD2828_W_Data(SigMode,channel,0xE5); //Normal GAMMA GREEN 
		      for(i=0; i<47; i++)
		      {
			      SSD2828_W_Data(SigMode,channel,ft_bufferG[i]);	
		      }	
				}
				else if((buffer[3]&0xFF)==0x02)
				{
					SSD2828_W_Reg(SigMode,channel,0xBC,48); 			
		      SSD2828_W_Cmd(SigMode,channel,0xBF);	
		      SSD2828_W_Data(SigMode,channel,0xE8); //Normal GAMMA BLUE
		      for(i=0; i<47; i++)
		      {
			      SSD2828_W_Data(SigMode,channel,ft_bufferB[i]);	
		      }	
				}
			}
			else if((buffer[4]&0xFF)==0x02)  //HBM
			{
				if((buffer[3]&0xFF)==0x00)
				{
					SSD2828_W_Reg(SigMode,channel,0xBC,48); 			
		      SSD2828_W_Cmd(SigMode,channel,0xBF);
		      SSD2828_W_Data(SigMode,channel,0xE3); //HBM GAMMA RED
		      for(i=0; i<47; i++)
		      {
			      SSD2828_W_Data(SigMode,channel,ft_bufferR[i]);
		      }
				}
				else if((buffer[3]&0xFF)==0x01)
				{
					SSD2828_W_Reg(SigMode,channel,0xBC,48);
		      SSD2828_W_Cmd(SigMode,channel,0xBF);	
		      SSD2828_W_Data(SigMode,channel,0xE6); //HBM GAMMA GREEN 
		      for(i=0; i<47; i++)
		      {
			      SSD2828_W_Data(SigMode,channel,ft_bufferG[i]);
		      }
				}
				else if((buffer[3]&0xFF)==0x02)
				{
					SSD2828_W_Reg(SigMode,channel,0xBC,48); 
		      SSD2828_W_Cmd(SigMode,channel,0xBF);	
		      SSD2828_W_Data(SigMode,channel,0xE9); //HBM GAMMA BLUE 
		      for(i=0; i<47; i++)
		      {
			      SSD2828_W_Data(SigMode,channel,ft_bufferB[i]);	
		      }		
				}
				
			}
			else if((buffer[4]&0xFF)==0x03)  //AOD
			{
				if((buffer[3]&0xFF)==0x00)
				{
					SSD2828_W_Reg(SigMode,channel,0xBC,48); 
		      SSD2828_W_Cmd(SigMode,channel,0xBF);	
		      SSD2828_W_Data(SigMode,channel,0xE1); //AOD GAMMA RED 
		      for(i=0; i<47; i++)
		      {
			      SSD2828_W_Data(SigMode,channel,ft_bufferR[i]);	
		      }	
				}
				else if((buffer[3]&0xFF)==0x01)
				{
					SSD2828_W_Reg(SigMode,channel,0xBC,48); 
		      SSD2828_W_Cmd(SigMode,channel,0xBF);	
		      SSD2828_W_Data(SigMode,channel,0xE4); // AOD GAMMA GREEN 
		      for(i=0; i<47; i++)
		      {
			      SSD2828_W_Data(SigMode,channel,ft_bufferG[i]);	
		      }		
				}
				else if((buffer[3]&0xFF)==0x02)
				{
						SSD2828_W_Reg(SigMode,channel,0xBC,48); 
		        SSD2828_W_Cmd(SigMode,channel,0xBF);	
		        SSD2828_W_Data(SigMode,channel,0xE7); //AOD GAMMA BLUE
		        for(i=0; i<47; i++)
		       {
			       SSD2828_W_Data(SigMode,channel,ft_bufferB[i]);	
		       }	
				}
					
			}
	  	
		
			
		SSD2828_W_Reg(SigMode,channel,0xB7,HS_B7_Data);				
		delay_ms(2); 
    buffer[0]=0x6C;	//FT2306
    buffer[1]=0x08;		
    buffer[4] = Uart_Error_None;
    buffer[5] = 0;
    STM2PC_RM671xx(pdev,CDC_IN_EP,buffer,buffer[2]+3);            //返回 写寄存器状态  ：ok   
}

void FT2306_Write_255G_Gamma(USBD_HandleTypeDef *pdev,uint8_t  ep_addr,u8 SigMode ,u8 channel,u8* buffer,u16 LP_B7_Data,u16 HS_B7_Data)
{
    u8 buffer1[7];
    u8 i,j,k=0,temp;
	  u8 m = 0x00;
					
		if((buffer[3]&0xFF)==0x00)
		{
			for( i = 0;i<2;i++)   //255绑点	                                                                                  
			{ft_bufferR[i+48]=buffer[i+53];}
	  }	
		else if((buffer[3]&0xFF)==0x42)
		{ 
			for( i = 0;i<2;i++)   //255绑点
			{ft_bufferG[i+48]=buffer[i+53];}
		}
		else if((buffer[3]&0xFF)==0x81)
		{	 
			for( i = 0;i<2;i++)   //255绑点
			{ft_bufferB[i+48]=buffer[i+53];}
	  }
		SSD2828_W_Reg(SigMode,channel,0xB7,(HS_B7_Data|0x0410)&0XFFFD);
		delay_ms(2);		

		buffer1[0] = 0x03;        
    buffer1[1] = 0xF0;
    buffer1[2] = 0xAA;
	  buffer1[3] = 0x13;
    SSD2828_W_Array(SigMode,channel,buffer1,0);		 
	  buffer1[0] = 0x02;        
    buffer1[1] = 0xC4;
    buffer1[2] = 0x01;
    SSD2828_W_Array(SigMode,channel,buffer1,0);		 		                                                                              			         
		buffer1[1] = 0xBF;
		buffer1[2] = buffer[4]; //gamma_group_sel
		SSD2828_W_Array(SigMode,channel,buffer1,0);		        
		delay_ms(5);
		
//------------------red/green/blue---------------------	 
		SSD2828_W_Reg(SigMode,channel,0xBC,3); 
		SSD2828_W_Cmd(SigMode,channel,0xBF);
		 
		SSD2828_W_Data(SigMode,channel,0xB3); //GAMMA RED GROUP4
		for(i=0; i<25; i++)
		{SSD2828_W_Data(SigMode,channel,ft_bufferR[i+48]);}
	
		SSD2828_W_Data(SigMode,channel,0xB7); //GAMMA GREEN GROUP3
		for(i=0; i<2; i++)
		{SSD2828_W_Data(SigMode,channel,ft_bufferG[i+48]);}
		 
		SSD2828_W_Data(SigMode,channel,0xBB); //GAMMA BLUE GROUP4
		for(i=0; i<2; i++)
		{SSD2828_W_Data(SigMode,channel,ft_bufferB[i+48]);}
		delay_ms(2); 				
    buffer1[2] = 0x02;				
    buffer1[1] = 0xC4;
    buffer1[2] = 0x00;    
    SSD2828_W_Array(SigMode,channel,buffer1,0);	
		
		SSD2828_W_Reg(SigMode,channel,0xB7,HS_B7_Data);		
		delay_ms(2); 				
    buffer[0]=0x6C;	//FT2306
    buffer[1]=0x08;		
    buffer[4] = Uart_Error_None;
    buffer[5] = 0;
    STM2PC_RM671xx(pdev,CDC_IN_EP,buffer,buffer[2]+3);            //返回 写寄存器状态  ：ok   
}

void FT2306_Read_Gamma(USBD_HandleTypeDef *pdev,uint8_t  ep_addr,u8 SigMode ,u8 channel,u8* buffer,u16 LP_B7_Data,u16 HS_B7_Data)
{
			u8 buffer1[7];
			u16 tmp;
			u8 i,j;				
					
	
	    			

			if((buffer[4]&0xFF)==0x01)  //NORMAL
			{
				if((buffer[3]&0xFF)==0x00)
				{
					SSD2828_W_Reg(SigMode,channel,0xB7,LP_B7_Data|0x0080);
	        SSD2828_W_Reg(SigMode,channel,0xC1,0x002F); //返回个数设置	    
	        delay_ms(2);			 
			    buffer1[0] = 0x02;        
          buffer1[1] = 0xE2;    // E2 NORMAL GAMMA RED        
          SSD2828_W_Array(SigMode,channel,buffer1,0);		 
	        delay_ms(2);                
			    SSD2828_W_Reg(SigMode,channel,0xD4,0x00FA);
		      SSD2828_W_Cmd(SigMode,channel,0xFF);
		      delay_ms(2);
					
						for(i=0;i<47;i++)
					{
						SSD2828_W_Cmd(SigMode,channel,0xFA);		
						tmp=SPI3_Read_u16_Data(channel);
						ft_bufferR[i]=tmp>>8;
						ft_bufferR[i+1]=tmp;
						delay_ms(5);
						i++;			
					}
				}
				else if((buffer[3]&0xFF)==0x01)
				{
					SSD2828_W_Reg(SigMode,channel,0xB7,LP_B7_Data|0x0080);
	        SSD2828_W_Reg(SigMode,channel,0xC1,0x002F); //返回个数设置	    
	        delay_ms(2);			 
			    buffer1[0] = 0x02;        
          buffer1[1] = 0xE5;    // E5 NORMAL GAMMA GREEN        
          SSD2828_W_Array(SigMode,channel,buffer1,0);		 
	        delay_ms(2);                
			    SSD2828_W_Reg(SigMode,channel,0xD4,0x00FA);
		      SSD2828_W_Cmd(SigMode,channel,0xFF);
		      delay_ms(2);
					
						for(i=0;i<47;i++)
					{
						SSD2828_W_Cmd(SigMode,channel,0xFA);		
						tmp=SPI3_Read_u16_Data(channel);
						ft_bufferG[i]=tmp>>8;
						ft_bufferG[i+1]=tmp;
						delay_ms(5);
						i++;			
					}
				}
				else if((buffer[3]&0xFF)==0x02)
				{
					SSD2828_W_Reg(SigMode,channel,0xB7,LP_B7_Data|0x0080);
	        SSD2828_W_Reg(SigMode,channel,0xC1,0x002F); //返回个数设置	    
	        delay_ms(2);			 
			    buffer1[0] = 0x02;        
          buffer1[1] = 0xE8;    // E8 NORMAL GAMMA BLUE        
          SSD2828_W_Array(SigMode,channel,buffer1,0);		 
	        delay_ms(2);                
			    SSD2828_W_Reg(SigMode,channel,0xD4,0x00FA);
		      SSD2828_W_Cmd(SigMode,channel,0xFF);
		      delay_ms(2);
					
						for(i=0;i<47;i++)
					{
						SSD2828_W_Cmd(SigMode,channel,0xFA);		
						tmp=SPI3_Read_u16_Data(channel);
						ft_bufferB[i]=tmp>>8;
						ft_bufferB[i+1]=tmp;
						delay_ms(5);
						i++;			
					}
				}
			}
			else if((buffer[4]&0xFF)==0x02)  //HBM
			{
				if((buffer[3]&0xFF)==0x00)
				{
					SSD2828_W_Reg(SigMode,channel,0xB7,LP_B7_Data|0x0080);
	        SSD2828_W_Reg(SigMode,channel,0xC1,0x002F); //返回个数设置	    
	        delay_ms(2);			 
			    buffer1[0] = 0x02;        
          buffer1[1] = 0xE3;    // E3 HBM GAMMA RED        
          SSD2828_W_Array(SigMode,channel,buffer1,0);		 
	        delay_ms(2);                
			    SSD2828_W_Reg(SigMode,channel,0xD4,0x00FA);
		      SSD2828_W_Cmd(SigMode,channel,0xFF);
		      delay_ms(2);
					
						for(i=0;i<47;i++)
					{
						SSD2828_W_Cmd(SigMode,channel,0xFA);		
						tmp=SPI3_Read_u16_Data(channel);
						ft_bufferR[i]=tmp>>8;
						ft_bufferR[i+1]=tmp;
						delay_ms(5);
						i++;			
					}
				}
				else if((buffer[3]&0xFF)==0x01)
				{
					SSD2828_W_Reg(SigMode,channel,0xB7,LP_B7_Data|0x0080);
	        SSD2828_W_Reg(SigMode,channel,0xC1,0x002F); //返回个数设置	    
	        delay_ms(2);			 
			    buffer1[0] = 0x02;        
          buffer1[1] = 0xE6;    // E6 HBM GAMMA GREEN        
          SSD2828_W_Array(SigMode,channel,buffer1,0);		 
	        delay_ms(2);                
			    SSD2828_W_Reg(SigMode,channel,0xD4,0x00FA);
		      SSD2828_W_Cmd(SigMode,channel,0xFF);
		      delay_ms(2);
					
						for(i=0;i<47;i++)
					{
						SSD2828_W_Cmd(SigMode,channel,0xFA);		
						tmp=SPI3_Read_u16_Data(channel);
						ft_bufferG[i]=tmp>>8;
						ft_bufferG[i+1]=tmp;
						delay_ms(5);
						i++;			
					}
				}
				else if((buffer[3]&0xFF)==0x02)
				{
					SSD2828_W_Reg(SigMode,channel,0xB7,LP_B7_Data|0x0080);
	        SSD2828_W_Reg(SigMode,channel,0xC1,0x002F); //返回个数设置	    
	        delay_ms(2);			 
			    buffer1[0] = 0x02;        
          buffer1[1] = 0xE9;    // E9 HBM GAMMA BLUE        
          SSD2828_W_Array(SigMode,channel,buffer1,0);		 
	        delay_ms(2);                
			    SSD2828_W_Reg(SigMode,channel,0xD4,0x00FA);
		      SSD2828_W_Cmd(SigMode,channel,0xFF);
		      delay_ms(2);
					
						for(i=0;i<47;i++)
					{
						SSD2828_W_Cmd(SigMode,channel,0xFA);		
						tmp=SPI3_Read_u16_Data(channel);
						ft_bufferB[i]=tmp>>8;
						ft_bufferB[i+1]=tmp;
						delay_ms(5);
						i++;			
					}
				}
			}
			else if((buffer[4]&0xFF)==0x03)  //AOD
			{
				if((buffer[3]&0xFF)==0x00)
				{
					SSD2828_W_Reg(SigMode,channel,0xB7,LP_B7_Data|0x0080);
	        SSD2828_W_Reg(SigMode,channel,0xC1,0x002F); //返回个数设置	    
	        delay_ms(2);			 
			    buffer1[0] = 0x02;        
          buffer1[1] = 0xE1;    // E1 AOD GAMMA RED        
          SSD2828_W_Array(SigMode,channel,buffer1,0);		 
	        delay_ms(2);                
			    SSD2828_W_Reg(SigMode,channel,0xD4,0x00FA);
		      SSD2828_W_Cmd(SigMode,channel,0xFF);
		      delay_ms(2);
					
						for(i=0;i<47;i++)
					{
						SSD2828_W_Cmd(SigMode,channel,0xFA);		
						tmp=SPI3_Read_u16_Data(channel);
						ft_bufferR[i]=tmp>>8;
						ft_bufferR[i+1]=tmp;
						delay_ms(5);
						i++;			
					}
				}
				else if((buffer[3]&0xFF)==0x01)
				{
					SSD2828_W_Reg(SigMode,channel,0xB7,LP_B7_Data|0x0080);
	        SSD2828_W_Reg(SigMode,channel,0xC1,0x002F); //返回个数设置	    
	        delay_ms(2);			 
			    buffer1[0] = 0x02;        
          buffer1[1] = 0xE4;    // E4 AOD GAMMA GREEN        
          SSD2828_W_Array(SigMode,channel,buffer1,0);		 
	        delay_ms(2);                
			    SSD2828_W_Reg(SigMode,channel,0xD4,0x00FA);
		      SSD2828_W_Cmd(SigMode,channel,0xFF);
		      delay_ms(2);
					
						for(i=0;i<47;i++)
					{
						SSD2828_W_Cmd(SigMode,channel,0xFA);		
						tmp=SPI3_Read_u16_Data(channel);
						ft_bufferG[i]=tmp>>8;
						ft_bufferG[i+1]=tmp;
						delay_ms(5);
						i++;			
					}
				}
				else if((buffer[3]&0xFF)==0x02)
				{
					SSD2828_W_Reg(SigMode,channel,0xB7,LP_B7_Data|0x0080);
	        SSD2828_W_Reg(SigMode,channel,0xC1,0x002F); //返回个数设置	    
	        delay_ms(2);			 
			    buffer1[0] = 0x02;        
          buffer1[1] = 0xE7;    // E7 AOD GAMMA BLUE        
          SSD2828_W_Array(SigMode,channel,buffer1,0);		 
	        delay_ms(2);                
			    SSD2828_W_Reg(SigMode,channel,0xD4,0x00FA);
		      SSD2828_W_Cmd(SigMode,channel,0xFF);
		      delay_ms(2);
					
						for(i=0;i<47;i++)
					{
						SSD2828_W_Cmd(SigMode,channel,0xFA);		
						tmp=SPI3_Read_u16_Data(channel);
						ft_bufferB[i]=tmp>>8;
						ft_bufferB[i+1]=tmp;
						delay_ms(5);
						i++;			
					}
				}
			}
		
					
			
			
			
		
		 if((buffer[3]&0xff)==0x00)       //GAMMA RED
	  {     
			for(j=0;j<47;j++)
			{
				buffer[4+j]=ft_bufferR[j];	  	
			}               			   
	  }
		else if((buffer[3]&0xff)==0x01)  //GAMMA GREEN
		{	
	    for(j=0;j<47;j++)
			{
				buffer[4+j]=ft_bufferG[j];	  		
			}              
		}
		else if((buffer[3]&0xff)==0x02)   //GAMMA BLUE
		{		
			for(j=0;j<47;j++)
			{
				buffer[4+j]=ft_bufferB[j];								
			}        
		} 
					
    buffer[0]=0x6C;	//FT2306
    buffer[1]=0x09;
		
		delay_ms(15);
    STM2PC_RM671xx(pdev,CDC_IN_EP,buffer,buffer[2]+3);          //返回 读取的 Gamma数据  ：ok  		

    SSD2828_W_Reg(SigMode,channel,0xB7,HS_B7_Data);
}

void FT2306_Gamma_OTP_Start(USBD_HandleTypeDef *pdev,uint8_t  ep_addr,u8 SigMode ,u8 channel,u8* buffer,u16 LP_B7_Data,u16 HS_B7_Data)
{
    u8 buffer1[10];
	  u8 mtp_flag;
	  SSD2828_W_Reg(SigMode,channel,0xB7,LP_B7_Data);
		delay_ms(15); 
    buffer1[0] = 0x01;
    buffer1[1] = 0x28;                    
    SSD2828_W_Array(SigMode,channel,buffer1,0); 
		delay_ms(10); 
	  buffer1[0] = 0x03;
    buffer1[1] = 0xF0; 
	  buffer1[2] = 0xAA;
	  buffer1[3] = 0x12;
    SSD2828_W_Array(SigMode,channel,buffer1,0); 
		delay_ms(1); 
	  buffer1[0] = 0x02;
    buffer1[1] = 0xCA; 
	  buffer1[2] = 0x01;
    SSD2828_W_Array(SigMode,channel,buffer1,0); 
		delay_ms(1); 		
		buffer1[0] = 0x04;
		buffer1[1] = 0xE6;	
		if(buffer[3]==0x0D)  //otp Gamma
		{	 
			buffer1[2] = 0x00;  
			buffer1[3] = 0x00;
			buffer1[4] = 0x80; 
		}
		else if(buffer[3]==0x0E)  //otp ALL
		{
			buffer1[2] = 0x9F;  
			buffer1[3] = 0x1F;
			buffer1[4] = 0x80;  
		}
		else if(buffer[3]==0x0F)  //otp PAGE 0
		{
			buffer1[2] = 0xB1;  
			buffer1[3] = 0x00;
			buffer1[4] = 0x00;  
		}
		else if(buffer[3]==0x1B)  //otp PAGE 1
		{	 
			buffer1[2] = 0x02;  
			buffer1[3] = 0x00;
			buffer1[4] = 0x00;  
		}
		else if(buffer[3]==0x1C)  //otp PAGE 2
		{
			buffer1[2] = 0x04;  
			buffer1[3] = 0x00;
			buffer1[4] = 0x00;  
		}
		else if(buffer[3]==0x1D)  //otp PAGE 5
		{
			buffer1[2] = 0x00;  
			buffer1[3] = 0x02;
			buffer1[4] = 0x00;  
		}
		else if(buffer[3]==0x1A)  //otp PAGE 4
		{		 
			buffer1[2] = 0x00;  
			buffer1[3] = 0x01;
			buffer1[4] = 0x00;  
		}
		else if(buffer[3]==0x1E)  //otp PAGE 7
		{
			buffer1[2] = 0x00;  
			buffer1[3] = 0x08;
			buffer1[4] = 0x00;  
		}
		else if(buffer[3]==0x1F)  //otp PAGE 8
		{
		//	buffer1[2] = 0x00;  
		//	buffer1[3] = 0x08;
		//	buffer1[4] = 0x00;  
		}		
		SSD2828_W_Array(SigMode,channel,buffer1,0); 
		delay_ms(5); 	 
    buffer1[0] = 0x04;
    buffer1[1] = 0xE7;
    buffer1[2] = 0x88;    
	  buffer1[3] = 0x55;    
	  buffer1[4] = 0x11;    
		SSD2828_W_Array(SigMode,channel,buffer1,0);	
		delay_ms(3000); 	
		buffer1[0] = 0x04;
		buffer1[1] = 0xE6;
		buffer1[2] = 0x00;  
		buffer1[3] = 0x00;
		buffer1[4] = 0x00;  
		SSD2828_W_Array(SigMode,channel,buffer1,0); 
		delay_ms(10); 
		buffer1[0] = 0x02;
		buffer1[1] = 0xCA;
		buffer1[2] = 0x02;  //
		SSD2828_W_Array(SigMode,channel,buffer1,0);     		 
		delay_ms(10);
//		buffer[1] = 0x0E;
		buffer[2] = 0x02;
		buffer[3] = Uart_Error_None;   //返回 OTP Gamma数据  ：OK
		buffer[4] = 0;
		STM2PC_RM671xx(pdev,CDC_IN_EP,buffer,buffer[2]+3);         
}
void FT2306_Read_Flash_ID(USBD_HandleTypeDef *pdev,uint8_t  ep_addr,u8 SigMode ,u8 channel,u8* buffer,u16 LP_B7_Data,u16 HS_B7_Data)
{
	  u8 buffer1[4]; 
	  u16 tmp;
		SSD2828_W_Reg(SigMode,channel,0xB7,LP_B7_Data);	
		delay_ms(5);
	  buffer1[0] = 0x01;
    buffer1[1] = 0x28;                    
    SSD2828_W_Array(SigMode,channel,buffer1,0);
    buffer1[0] = 0x03;
    buffer1[1] = 0xF0; 
	  buffer1[2] = 0xAA; 
	  buffer1[3] = 0x10; 
    SSD2828_W_Array(SigMode,channel,buffer1,0);
    buffer1[1] = 0xEA; 
	  buffer1[2] = 0x30; 
	  buffer1[3] = 0x00; 
    SSD2828_W_Array(SigMode,channel,buffer1,0);	   
	  buffer1[0] = 0x02;
    buffer1[1] = 0xEE; 
	  buffer1[2] = 0xAB; 
    SSD2828_W_Array(SigMode,channel,buffer1,0);
	
    buffer1[1] = 0xED; 
	  buffer1[2] = 0x20; 
    SSD2828_W_Array(SigMode,channel,buffer1,0);	
		delay_ms(100);  
    buffer1[1] = 0xED; 
	  buffer1[2] = 0x00; 
    SSD2828_W_Array(SigMode,channel,buffer1,0);	
    buffer1[1] = 0xEE; 
	  buffer1[2] = 0x06; 
    SSD2828_W_Array(SigMode,channel,buffer1,0);	
    buffer1[1] = 0xED; 
	  buffer1[2] = 0x20; 
    SSD2828_W_Array(SigMode,channel,buffer1,0);
    delay_ms(100); 		
    buffer1[1] = 0xED; 
	  buffer1[2] = 0x00; 
    SSD2828_W_Array(SigMode,channel,buffer1,0);	
    buffer1[1] = 0xEE; 
	  buffer1[2] = 0x05; 
    SSD2828_W_Array(SigMode,channel,buffer1,0);	
    buffer1[1] = 0xED; 
	  buffer1[2] = 0x08; 
    SSD2828_W_Array(SigMode,channel,buffer1,0);	
		delay_ms(100); 
    buffer1[1] = 0xED; 
	  buffer1[2] = 0x00; 
    SSD2828_W_Array(SigMode,channel,buffer1,0);	
		delay_ms(100); 
    buffer1[1] = 0xEE; 
	  buffer1[2] = 0x9F; 
    SSD2828_W_Array(SigMode,channel,buffer1,0);	
    buffer1[1] = 0xED; 
	  buffer1[2] = 0x44; 
    SSD2828_W_Array(SigMode,channel,buffer1,0);	
		delay_ms(100);
    buffer1[1] = 0xED; 
	  buffer1[2] = 0x00; 
    SSD2828_W_Array(SigMode,channel,buffer1,0);
		/***read***/
		SSD2828_W_Reg(SigMode,channel,0xB7,0x0200|0x0080);                               
    SSD2828_W_Reg(SigMode,channel,0xC1,0x0003); //return package size                                
    SSD2828_W_Reg(SigMode,channel,0xC0,0x0001);
    buffer1[0] = 0x01;
    buffer1[1] = 0xEC;                        
    SSD2828_W_Array(SigMode,channel,buffer1,0);
    delay_ms(5);  
    SSD2828_W_Reg(SigMode,channel,0xD4,0x00FA);
    SSD2828_W_Cmd(SigMode,channel,0xFF);
		for(int i =0;i<1;i++)
		{
			 SSD2828_W_Cmd(SigMode,channel,0xFA);		
       tmp=SPI3_Read_u16_Data(channel);
			 buffer[3+i]=tmp>>8;
       buffer[4+i]=tmp;
       delay_ms(2);
		}
   
    buffer[0]=0x6C;	
		buffer[1]=0x20;
		buffer[2]=0x02;
		//SSD2828_W_Reg(SigMode,channel,0xB7,HS_B7_Data);
		SSD2828_W_Reg(SigMode,channel,0xB7,LP_B7_Data);
    STM2PC_RM671xx(pdev,CDC_IN_EP,buffer,buffer[2]+3);  
}

void FT2306_Erase_Flash(USBD_HandleTypeDef *pdev,uint8_t  ep_addr,u8 SigMode ,u8 channel,u8* buffer,u16 LP_B7_Data,u16 HS_B7_Data)
{
	  SSD2828_W_Reg(SigMode,channel,0xB7,LP_B7_Data);
	  u8 buffer1[4]; 
	  buffer1[0] = 0x02;
    buffer1[1] = 0xEE;
	  buffer1[2] = 0x60;
    SSD2828_W_Array(SigMode,channel,buffer1,0);
    buffer1[1] = 0xED;
	  buffer1[2] = 0x20;
    SSD2828_W_Array(SigMode,channel,buffer1,0);	
	  delay_ms(8000);   
    buffer1[1] = 0xED;
	  buffer1[2] = 0x00;
    SSD2828_W_Array(SigMode,channel,buffer1,0);
	
	//  buffer[4] = Uart_Error_None;
  //  STM2PC_RM671xx(pdev,CDC_IN_EP,buffer,buffer[2]+3);           //返回 写2810状态  ：ok
}

void FT2306_Flash_Statu(USBD_HandleTypeDef *pdev,uint8_t  ep_addr,u8 SigMode ,u8 channel,u8* buffer,u16 LP_B7_Data,u16 HS_B7_Data)
{
	  SSD2828_W_Reg(SigMode,channel,0xB7,0x0200);
	  u8 buffer1[6]; 
	  u16 tmp;
	  buffer1[0] = 0x02;
    buffer1[1] = 0x59;
	  buffer1[2] = 0x11;
    SSD2828_W_Array(SigMode,channel,buffer1,0);
		buffer1[0] = 0x02;
    buffer1[1] = 0x6F;
	  buffer1[2] = 0x03;
    SSD2828_W_Array(SigMode,channel,buffer1,0);
	  buffer1[0] = 0x03;
    buffer1[1] = 0xF0;
	  buffer1[2] = 0xAA;
	  buffer1[3] = 0x10;
    SSD2828_W_Array(SigMode,channel,buffer1,0);
	  buffer1[0] = 0x02;
    buffer1[1] = 0xB8;
	  buffer1[2] = 0x04;
    SSD2828_W_Array(SigMode,channel,buffer1,0);
		buffer1[0] = 0x03;
    buffer1[1] = 0xEA;
	  buffer1[2] = 0x30;
	  buffer1[3] = 0x20;
    SSD2828_W_Array(SigMode,channel,buffer1,0);	
		buffer1[0] = 0x01;
    buffer1[1] = 0x11;                    
    SSD2828_W_Array(SigMode,channel,buffer1,0);
		buffer1[0] = 0x02;
    buffer1[1] = 0xEE;
	  buffer1[2] = 0xAB;
    SSD2828_W_Array(SigMode,channel,buffer1,0);
    buffer1[1] = 0xED;
	  buffer1[2] = 0x20;
    SSD2828_W_Array(SigMode,channel,buffer1,0);	
		delay_ms(100);  
    buffer1[1] = 0xED;
	  buffer1[2] = 0x00;
    SSD2828_W_Array(SigMode,channel,buffer1,0);
    buffer1[1] = 0xEE;
	  buffer1[2] = 0x06;
    SSD2828_W_Array(SigMode,channel,buffer1,0);
    buffer1[1] = 0xED;
	  buffer1[2] = 0x20;
    SSD2828_W_Array(SigMode,channel,buffer1,0);
		delay_ms(100);  
    buffer1[1] = 0xED;
	  buffer1[2] = 0x00;
    SSD2828_W_Array(SigMode,channel,buffer1,0);
    buffer1[1] = 0xEE;
	  buffer1[2] = 0x05;
    SSD2828_W_Array(SigMode,channel,buffer1,0);
    buffer1[1] = 0xED;
	  buffer1[2] = 0x08;
    SSD2828_W_Array(SigMode,channel,buffer1,0);
		delay_ms(100);  
    buffer1[1] = 0xED;
	  buffer1[2] = 0x00;
    SSD2828_W_Array(SigMode,channel,buffer1,0);
		delay_ms(100);  
    buffer1[1] = 0xEE;
	  buffer1[2] = 0x01;
    SSD2828_W_Array(SigMode,channel,buffer1,0);  
    buffer1[1] = 0x65;
	  buffer1[2] = 0x07;
    SSD2828_W_Array(SigMode,channel,buffer1,0);
    buffer1[0] = 0x03;
    buffer1[1] = 0xEE;
	  buffer1[2] = 0x02;
		buffer1[3] = 0x02;
    SSD2828_W_Array(SigMode,channel,buffer1,0);
    delay_ms(100); 
    buffer1[0] = 0x02;
    buffer1[1] = 0xED;
	  buffer1[2] = 0x10;
    SSD2828_W_Array(SigMode,channel,buffer1,0);
		delay_ms(100);  
    buffer1[1] = 0xED;
	  buffer1[2] = 0x00;
    SSD2828_W_Array(SigMode,channel,buffer1,0);
		delay_ms(100); 
    buffer1[1] = 0xEE;
	  buffer1[2] = 0x06;
    SSD2828_W_Array(SigMode,channel,buffer1,0);
    buffer1[1] = 0xED;
	  buffer1[2] = 0x20;
    SSD2828_W_Array(SigMode,channel,buffer1,0);
		delay_ms(100);
    buffer1[1] = 0xED;
	  buffer1[2] = 0x00;
    SSD2828_W_Array(SigMode,channel,buffer1,0);
    buffer1[1] = 0xEE;
	  buffer1[2] = 0x05;
    SSD2828_W_Array(SigMode,channel,buffer1,0);
    buffer1[1] = 0xED;
	  buffer1[2] = 0x08;
    SSD2828_W_Array(SigMode,channel,buffer1,0);
		delay_ms(100);
    buffer1[1] = 0xED;
	  buffer1[2] = 0x00;
    SSD2828_W_Array(SigMode,channel,buffer1,0);
		delay_ms(100);
    buffer1[1] = 0xEE;
	  buffer1[2] = 0x35;
    SSD2828_W_Array(SigMode,channel,buffer1,0);
    buffer1[1] = 0xED;
	  buffer1[2] = 0x08;
    SSD2828_W_Array(SigMode,channel,buffer1,0);
		delay_ms(100);
    buffer1[1] = 0xED;
	  buffer1[2] = 0x00;
    SSD2828_W_Array(SigMode,channel,buffer1,0);
		delay_ms(100);
		
	/*	
    buffer1[1] = 0x65;
	  buffer1[2] = 0x04;
    SSD2828_W_Array(SigMode,channel,buffer1,0);
	  buffer1[0] = 0x04;
    buffer1[1] = 0xEE;
	  buffer1[2] = 0x00;
	  buffer1[3] = 0x00;
	  buffer1[4] = 0x00;
    SSD2828_W_Array(SigMode,channel,buffer1,0);
	  buffer1[0] = 0x03;
    buffer1[1] = 0xEE;
	  buffer1[2] = 0x0B;
	  buffer1[3] = 0x08;
    SSD2828_W_Array(SigMode,channel,buffer1,0);
	  buffer1[0] = 0x02;
    buffer1[1] = 0xED;
	  buffer1[2] = 0x04;
    SSD2828_W_Array(SigMode,channel,buffer1,0);
		delay_ms(100);
    buffer1[1] = 0xED;
	  buffer1[2] = 0x00;
    SSD2828_W_Array(SigMode,channel,buffer1,0);
		delay_ms(50);
	*/	
		SSD2828_W_Reg(SigMode,channel,0xB7,0x0200|0x0080);                               
    SSD2828_W_Reg(SigMode,channel,0xC1,0x0003); //return package size                                
    //SSD2828_W_Reg(SigMode,channel,0xC0,0x0001);
    buffer1[0] = 0x01;
    buffer1[1] = 0xEF;                        
    SSD2828_W_Array(SigMode,channel,buffer1,0);
    delay_ms(5);  
    SSD2828_W_Reg(SigMode,channel,0xD4,0x00FA);
    SSD2828_W_Cmd(SigMode,channel,0xFF);
		
    for(int i =0;i<2;i++)
		{
			SSD2828_W_Cmd(SigMode,channel,0xFA);		
			tmp=SPI3_Read_u16_Data(channel);
			buffer[4+i]=tmp>>8;
			buffer[5+i]=tmp;
			delay_ms(5);
		}
 
		//  buffer[0]=0x4D;	
		//	buffer[1]=0x22;
		//	buffer[4] = Uart_Error_None;
		//  SSD2828_W_Reg(SigMode,channel,0xB7,HS_B7_Data);
		//	SSD2828_W_Reg(SigMode,channel,0xB7,LP_B7_Data);
		//  STM2PC_RM671xx(pdev,CDC_IN_EP,buffer,buffer[2]+3); 
}

void FT2306_Check_Flash(USBD_HandleTypeDef *pdev,uint8_t  ep_addr,u8 SigMode ,u8 channel,u8* buffer,u16 LP_B7_Data,u16 HS_B7_Data)
{
		SSD2828_W_Reg(SigMode,channel,0xB7,LP_B7_Data);
	  u8 buffer1[5]; 
	  u16 tmp;
	  buffer1[0] = 0x02;
    buffer1[1] = 0x65;
	  buffer1[2] = 0x04;
    SSD2828_W_Array(SigMode,channel,buffer1,0);
	
	  buffer1[0] = 0x04;
    buffer1[1] = 0xEE;
	  buffer1[2] = 0x00;
	  buffer1[3] = 0x00;
	  buffer1[4] = 0x00;
    SSD2828_W_Array(SigMode,channel,buffer1,0);
	
	  buffer1[0] = 0x03;
    buffer1[1] = 0xEE;
	  buffer1[2] = 0x0B;
	  buffer1[3] = 0x08;
    SSD2828_W_Array(SigMode,channel,buffer1,0);
	
	  buffer1[0] = 0x02;
    buffer1[1] = 0xED;
	  buffer1[2] = 0x04;
    SSD2828_W_Array(SigMode,channel,buffer1,0);
		delay_ms(100);
		
		buffer1[0] = 0x02;
    buffer1[1] = 0xED;
	  buffer1[2] = 0x00;
    SSD2828_W_Array(SigMode,channel,buffer1,0);
		delay_ms(50);
		
		/***********************************************
		buffer1[0] = 0x02;
    buffer1[1] = 0x65;
	  buffer1[2] = 0x08;
    SSD2828_W_Array(SigMode,channel,buffer1,0);
	
	  buffer1[0] = 0x04;
    buffer1[1] = 0xEA;
	  buffer1[2] = 0x1F;
	  buffer1[3] = 0xCC;
	  buffer1[4] = 0x3A;
    SSD2828_W_Array(SigMode,channel,buffer1,0);
	
	  buffer1[0] = 0x03;
    buffer1[1] = 0xFF;
	  buffer1[2] = 0x5A;
	  buffer1[3] = 0x80;
    SSD2828_W_Array(SigMode,channel,buffer1,0);
	
	  buffer1[0] = 0x02;
    buffer1[1] = 0xFA;
	  buffer1[2] = 0x01;
    SSD2828_W_Array(SigMode,channel,buffer1,0);
		*****************************************************/
		
		
		SSD2828_W_Reg(SigMode,channel,0xB7,LP_B7_Data|0x0080);                               
    SSD2828_W_Reg(SigMode,channel,0xC1,0x0009); //return package size                                
    SSD2828_W_Reg(SigMode,channel,0xC0,0x0001);
    buffer1[0] = 0x01;
    buffer1[1] = 0xEC;                        
    SSD2828_W_Array(SigMode,channel,buffer1,0);
    delay_ms(5);  
    SSD2828_W_Reg(SigMode,channel,0xD4,0x00FA);
    SSD2828_W_Cmd(SigMode,channel,0xFF);
		 for(i=0;i<8;i++)
    {
        SSD2828_W_Cmd(SigMode,channel,0xFA);		
        tmp=SPI3_Read_u16_Data(channel);
        buffer[4+i]=tmp>>8;
        buffer[5+i]=tmp;
        delay_ms(2);
        i++;
    }
 
	//   buffer[0]=0x4D;	
	//	buffer[1]=0x23;
	//	buffer[2]=0x08;
	//	buffer[4] = Uart_Error_None;
	//    SSD2828_W_Reg(SigMode,channel,0xB7,HS_B7_Data);
	//   SSD2828_W_Reg(SigMode,channel,0xB7,LP_B7_Data);
	//   STM2PC_RM671xx(pdev,CDC_IN_EP,buffer,buffer[2]+3); 	  
}

void FT2306_Step_Five(USBD_HandleTypeDef *pdev,uint8_t  ep_addr,u8 SigMode ,u8 channel,u8* buffer,u16 LP_B7_Data,u16 HS_B7_Data)
{
	  SSD2828_W_Reg(SigMode,channel,0xB7,LP_B7_Data);
	  u8 buffer1[5]; 
	  buffer1[0] = 0x02;
    buffer1[1] = 0x65;
	  buffer1[2] = 0x08;
    SSD2828_W_Array(SigMode,channel,buffer1,0);
	
	  buffer1[0] = 0x04;
    buffer1[1] = 0xEA;
	  buffer1[2] = 0x1F;
	  buffer1[3] = 0xCC;
	  buffer1[4] = 0x20;
    SSD2828_W_Array(SigMode,channel,buffer1,0);
	
	  buffer1[0] = 0x03;
    buffer1[1] = 0xFF;
	  buffer1[2] = 0x5A;
	  buffer1[3] = 0x80;
    SSD2828_W_Array(SigMode,channel,buffer1,0);
	
	  buffer1[0] = 0x02;
    buffer1[1] = 0xFA;
	  buffer1[2] = 0x01;
    SSD2828_W_Array(SigMode,channel,buffer1,0);
		
		SSD2828_W_Reg(SigMode,channel,0xB7,HS_B7_Data);  //回到高速
		delay_ms(5);
//		buffer[4] = Uart_Error_None;
//    STM2PC_RM671xx(pdev,CDC_IN_EP,buffer,buffer[2]+3);           //返回 写2810状态  ：ok
}

void FT2306_OTP_Flash(USBD_HandleTypeDef *pdev,uint8_t  ep_addr,u8 SigMode ,u8 channel,u8* buffer,u16 LP_B7_Data,u16 HS_B7_Data)
{
	  u8 buffer1[6]; 	
	  SSD2828_W_Reg(SigMode,channel,0xB7,LP_B7_Data);
		delay_ms(5);	
	
	  buffer1[0] = 0x05;
    buffer1[1] = 0xEE;
	  buffer1[2] = 0x32;
	  buffer1[3] = 0x00;
	  buffer1[4] = 0x01;
	  buffer1[5] = 0x00;
    SSD2828_W_Array(SigMode,channel,buffer1,0);
	  delay_ms(100);	 
	  buffer1[0] = 0x02;
    buffer1[1] = 0xED;
	  buffer1[2] = 0x02;
	  SSD2828_W_Array(SigMode,channel,buffer1,0);
	  delay_ms(9000);
		//delay_ms(60000);	
	  buffer1[0] = 0x02;
    buffer1[1] = 0xED;
	  buffer1[2] = 0x00;
	  SSD2828_W_Array(SigMode,channel,buffer1,0);
	  buffer1[0] = 0x03;
    buffer1[1] = 0xFF;
	  buffer1[2] = 0x5A;
		buffer1[3] = 0x80;
	  SSD2828_W_Array(SigMode,channel,buffer1,0);
	
	  buffer1[0] = 0x02;
    buffer1[1] = 0x01;
	  buffer1[2] = 0x00;
	  SSD2828_W_Array(SigMode,channel,buffer1,0);
		delay_ms(100);
		
		////add  reset
		//Set_2828_reset(OLED.SigMode);       //复位2828和OLED
		SSD_RESET_LOW;		//复位SSD2828芯片
		delay_ms(100);
		SSD_RESET_HIGH;		
		delay_ms(50); 			
		
//		buffer[0]=0x4D;	
//		buffer[1]=0x25;
//		buffer[2]=0x02;

//		buffer[4] = Uart_Error_None;
//    STM2PC_RM671xx(pdev,CDC_IN_EP,buffer,buffer[2]+3);           //返回 写2810状态  ：ok
}

void FT2306_CRC_check(USBD_HandleTypeDef *pdev,uint8_t  ep_addr,u8 SigMode ,u8 channel,u8* buffer,u16 LP_B7_Data,u16 HS_B7_Data)
{
		u8 buffer1[5]; 
	  u16 tmp;
		delay_ms(5000);	
		SSD2828_W_Reg(SigMode,channel,0xB7,LP_B7_Data);
	  delay_ms(5);

	  buffer1[0] = 0x03;
    buffer1[1] = 0xFF;
	  buffer1[2] = 0x5A;
	  buffer1[3] = 0x80;
    SSD2828_W_Array(SigMode,channel,buffer1,0);
		
		SSD2828_W_Reg(SigMode,channel,0xB7,LP_B7_Data|0x0080);                               
    SSD2828_W_Reg(SigMode,channel,0xC1,0x0009); //return package size                                
    SSD2828_W_Reg(SigMode,channel,0xC0,0x0001);
    buffer1[0] = 0x01;
    buffer1[1] = 0xfa;                        
    SSD2828_W_Array(SigMode,channel,buffer1,0);
    delay_ms(5);  
    SSD2828_W_Reg(SigMode,channel,0xD4,0x00FA);
    SSD2828_W_Cmd(SigMode,channel,0xFF);
		 for(i=0;i<9;i++)
    {
        SSD2828_W_Cmd(SigMode,channel,0xFA);		
        tmp=SPI3_Read_u16_Data(channel);
        buffer[3+i]=tmp>>8;
        buffer[4+i]=tmp;
        delay_ms(2);
        i++;
    }
//    buffer[0]=0x4D;	
//		buffer[1]=0x26;
//		buffer[2]=0x09;
//		//buffer[4] = Uart_Error_None;
//    SSD2828_W_Reg(SigMode,channel,0xB7,LP_B7_Data);
//    STM2PC_RM671xx(pdev,CDC_IN_EP,buffer,buffer[2]+3); 	  
}

void FT2306_Demura_on(USBD_HandleTypeDef *pdev,uint8_t  ep_addr,u8 SigMode ,u8 channel,u8* buffer,u16 LP_B7_Data,u16 HS_B7_Data)
{
		u8 buffer1[5]; 
		SSD2828_W_Reg(SigMode,channel,0xB7,LP_B7_Data);
	  delay_ms(5);	
	  buffer1[0] = 0x02;
    buffer1[1] = 0x59;
	  buffer1[2] = 0x09;
		SSD2828_W_Array(SigMode,channel,buffer1,0);	
    SSD2828_W_Reg(SigMode,channel,0xB7,HS_B7_Data);
		delay_ms(5);
    STM2PC_RM671xx(pdev,CDC_IN_EP,buffer,buffer[2]+3); 	  	
}

void FT2306_Demura_off(USBD_HandleTypeDef *pdev,uint8_t  ep_addr,u8 SigMode ,u8 channel,u8* buffer,u16 LP_B7_Data,u16 HS_B7_Data)
{
		u8 buffer1[5]; 
		SSD2828_W_Reg(SigMode,channel,0xB7,LP_B7_Data);
	  delay_ms(5);	
	  buffer1[0] = 0x02;
    buffer1[1] = 0x59;
	  buffer1[2] = 0x00;
		SSD2828_W_Array(SigMode,channel,buffer1,0);	
    SSD2828_W_Reg(SigMode,channel,0xB7,HS_B7_Data);
		delay_ms(5);
    STM2PC_RM671xx(pdev,CDC_IN_EP,buffer,buffer[2]+3); 	  	
}

void ProcessForIc6C( USBD_HandleTypeDef *pdev,uint8_t  ep_addr,u8 SigMode ,u8 channel,u8 buffer[],u16 LP_B7_Data,u16 HS_B7_Data)
{	
	switch(buffer[1])
	{
		case 0x01:                                      //写寄存器
			FT2306_Write_Register(pdev,ep_addr,SigMode,channel,buffer,LP_B7_Data,HS_B7_Data);break;	
		case 0x02:                                      //读寄存器
			FT2306_Read_Register(pdev,ep_addr,SigMode,channel,buffer,LP_B7_Data,HS_B7_Data);break;		
		case 0x03:                                      //读寄存器
			FT2306_Write_255G_Gamma(pdev,ep_addr,SigMode,channel,buffer,LP_B7_Data,HS_B7_Data);break;				
		case 0x08:                                      //写Gamma数据    
			FT2306_Write_Gamma(pdev,ep_addr,SigMode,channel,buffer,LP_B7_Data,HS_B7_Data);break;
		case 0x09:                                      //读Gamma数据
			FT2306_Read_Gamma(pdev,ep_addr,SigMode,channel,buffer,LP_B7_Data,HS_B7_Data);break; 
		case 0x0D://OTP Gamma
			FT2306_Gamma_OTP_Start(pdev,ep_addr,SigMode,channel,buffer,LP_B7_Data,HS_B7_Data);  break;
		case 0x20:                                      //读Flash ID  
			FT2306_Read_Flash_ID(pdev,ep_addr,SigMode,channel,buffer,LP_B7_Data,HS_B7_Data);break;
		case 0x21:                                      //擦除Demura数据    
			FT2306_Erase_Flash(pdev,ep_addr,SigMode,channel,buffer,LP_B7_Data,HS_B7_Data);break;
		case 0x22:                                   
			FT2306_Flash_Statu(pdev,ep_addr,SigMode,channel,buffer,LP_B7_Data,HS_B7_Data);break;
		case 0x23:
			FT2306_Check_Flash(pdev,ep_addr,SigMode,channel,buffer,LP_B7_Data,HS_B7_Data);break;
		case 0x24:                                     
			FT2306_Step_Five(pdev,ep_addr,SigMode,channel,buffer,LP_B7_Data,HS_B7_Data);break;
		case 0x25:
			FT2306_OTP_Flash(pdev,ep_addr,SigMode,channel,buffer,LP_B7_Data,HS_B7_Data);break;
		case 0x26:
			FT2306_CRC_check(pdev,ep_addr,SigMode,channel,buffer,LP_B7_Data,HS_B7_Data);break;		
		case 0x27:
			FT2306_Demura_on(pdev,ep_addr,SigMode,channel,buffer,LP_B7_Data,HS_B7_Data);break;		
		case 0x28:
			FT2306_Demura_off(pdev,ep_addr,SigMode,channel,buffer,LP_B7_Data,HS_B7_Data);break;		
    default:	break;	
	}	
}


